// import './public-path'
import { createApp, App as AppInstance } from "vue";
import {
  createRouter,
  createWebHistory,
  createWebHashHistory,
  RouterHistory,
  Router,
} from "vue-router";
import App from "./App.vue";
import routes from "./router";
import "normalize.css/normalize.css";
import Antd from "ant-design-vue";
import "ant-design-vue/dist/antd.less";
import "./assets/css/base.scss";
// import SvgIcon from '@/components/SvgIcon.vue'
import { FontAwesomeIcon } from "@fortawesome/vue-fontawesome";

import store from "./store";

let app: AppInstance | null = null;
let router: Router | null = null;
let history: RouterHistory | null = null;

// 获取用户登陆信息
if (!window.__MicroAPP__) {
  window.__MicroAPP__ = window.parent.__MicroAPP__;
}

// 将渲染操作放入 mount 函数
function mount() {
  history = createWebHistory(import.meta.env.BASE_URL);
  router = createRouter({
    history,
    routes,
  });

  app = createApp(App);
  app
    .component("font-awesome-icon", FontAwesomeIcon)
    .use(Antd)
    .use(router)
    .use(store)
    .mount("#vite-ai-app-demo");
  // fixBugForVueRouter4(router)
}

// 将卸载操作放入 unmount 函数
function unmount() {
  app?.unmount();
  history?.destroy();
  app = null;
  router = null;
  history = null;
}
if (!window.__MicroAPP__) {
  window.__MicroAPP__ = window.parent.__MicroAPP__;
}
if (window.__MicroAPP__) {
  window.__MicroAPP__.basic.initApp({
    win: window,
    type: "vite",
    mount,
    unmount,
  });
} else {
  mount();
}
